home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / wvnsrc75.zip / WVPOST.C < prev    next >
C/C++ Source or Header  |  1993-01-11  |  7KB  |  320 lines

  1. /*--- WVPOST.C ------------------------------------------------------------
  2.  *
  3.  *    This file contains the window procedure for the "posting" windows,
  4.  *    windows in which the user edits the text of an article to be posted.
  5.  *
  6.  *    Mark Riordan   27 Jan 1990
  7.  */
  8.  
  9. #include "windows.h"
  10. #include "wvglob.h"
  11. #include "winvn.h"
  12. #ifndef MAC
  13. #include "winundoc.h"
  14. #endif
  15.  
  16. long FAR PASCAL 
  17. WinVnPostWndProc (hWnd, message, wParam, lParam)
  18.      HWND hWnd;
  19.      unsigned message;
  20.      WPARAM wParam;
  21.      LPARAM lParam;
  22. {
  23.   FARPROC lpProcAbout;
  24.   HMENU hMenu;
  25.  
  26.   PAINTSTRUCT ps;        /* paint structure          */
  27.  
  28.   HDC hDC;            /* handle to display context */
  29.   HWND hWndPost, hWndPostEdit;
  30. #ifdef MAC
  31.   TEHandle TEH;
  32.   Rect myClipRect;
  33. #endif
  34.   HDC hDCView;
  35.   int ih, j;
  36.   int found;
  37.   int imemo;
  38.   TypDoc *MyDoc;
  39.   char mesbuf[348];        /*** debug */
  40.  
  41.   for (ih = 0, found = FALSE; !found && ih < MAXPOSTWNDS; ih++)
  42.     {
  43.       if (hWndPosts[ih] == hWnd)
  44.     {
  45. #ifndef MAC
  46.       hWndPostEdit = hWndPostEdits[ih];
  47. #else
  48.       TEH = TEHPosts[ih];
  49. #endif
  50.       found = TRUE;
  51.       break;
  52.     }
  53.     }
  54.   if (!found && message == WM_CREATE)
  55.     {
  56.       for (ih = 0; !found && ih < MAXVIEWS; ih++)
  57.     {
  58.       if (!hWndPosts[ih])
  59.         {
  60.           found = TRUE;
  61.           hWndPosts[ih] = hWnd;
  62.           break;
  63.         }
  64.     }
  65.     }
  66. #if 0
  67.   if (!found)
  68.     {
  69.       MessageBox (hWnd, "Can't find Post hWnd", "Error!", MB_OK | MB_ICONHAND);
  70.       DestroyWindow (hWnd);
  71.       return (NULL);        /*** ? */
  72.     }
  73. #endif
  74.  
  75.   switch (message)
  76.     {
  77.     case WM_SYSCOMMAND:
  78.       return (DefWindowProc (hWnd, message, wParam, lParam));
  79.  
  80.     case WM_CREATE:
  81. #ifndef MAC
  82.       hWndPostEdit = hWndPostEdits[ih] = CreateWindow ("edit", (char *) NULL,
  83.          WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER
  84.                           | ES_LEFT | ES_MULTILINE |
  85.                          ES_AUTOHSCROLL | ES_AUTOVSCROLL
  86.                                ,
  87.                                0, 0, 0, 0,
  88.                          hWnd, EDITID, hInst, NULL);
  89.       sprintf (mesbuf, "hWndPostEdits[%d] = %5d\r\n       ", ih, hWndPostEdits[ih]);
  90.       /*   MessageBox(hWnd,mesbuf,"Edit Window Results",MB_OK|MB_ICONASTERISK); */
  91.       SetWindowText (hWndPostEdits[ih], mesbuf);
  92. #endif
  93. #if 0
  94.       {
  95.     long int freeHeap = FreeMem ();
  96.     long int biggestBlock = MaxBlock ();
  97.     long int freeStack = StackSpace ();
  98.     long int el;
  99.  
  100.     el = 0;
  101.     sprintf (mesbuf, "FreeMem=%ld  MaxBlock=%ld  StackSpace=%ld",
  102.          freeHeap, biggestBlock, freeStack);
  103.     MessageBox (hWnd, mesbuf, "Available Memory", MB_OK);
  104.       }
  105. #endif
  106.       CreatePostingText (PostDoc, hWnd, hWndPostEdit, DOCTYPE_POSTING);
  107.       /*   SetFocus(hWndEdits[ih]);  */
  108.       break;
  109.  
  110.     case WM_SIZE:
  111. #ifndef MAC
  112.       MoveWindow (hWndPostEdit, 0, 0, LOWORD (lParam),
  113.           HIWORD (lParam), TRUE);
  114. #endif
  115.       break;
  116.  
  117.     case WM_SETFOCUS:
  118.       SetFocus (hWndPostEdit);
  119.       break;
  120.  
  121.     case WM_KEYDOWN:
  122.       if (wParam == VK_F6)
  123.     {
  124.       NextWindow (&(PostingDocs[ih]));
  125.     }
  126.       break;
  127.  
  128. #ifdef MAC
  129.     case WM_PAINT:
  130.       if (TEH)
  131.     {
  132.       myClipRect = hWnd->portRect;
  133.       myClipRect.right -= SBarWidth;
  134.       myClipRect.bottom -= SBarWidth;
  135.       (*TEH)->viewRect = myClipRect;
  136.       TEUpdate (&myClipRect, TEH);
  137.     }
  138.       break;
  139.  
  140. #endif
  141.  
  142.     case WM_COMMAND:
  143.       switch (wParam)
  144.     {
  145.     case IDM_CANCEL:
  146.     case IDV_EXIT:
  147.       DestroyWindow (hWnd);
  148.       break;
  149.  
  150.     case IDM_POST:
  151.       StartPost (ih);
  152.       break;
  153.  
  154.     case IDM_UNDO:
  155.       SendMessage (hWndPostEdit, WM_UNDO, 0, 0L);
  156.       break;
  157.  
  158.     case IDM_CUT:
  159.       SendMessage (hWndPostEdit, WM_CUT, 0, 0L);
  160.       break;
  161.  
  162.     case IDM_COPY:
  163.       SendMessage (hWndPostEdit, WM_COPY, 0, 0L);
  164.       break;
  165.  
  166.     case IDM_PASTE:
  167.       SendMessage (hWndPostEdit, WM_PASTE, 0, 0L);
  168.       break;
  169.  
  170.     case IDM_CLEAR:
  171.       SendMessage (hWndPostEdit, WM_CLEAR, 0, 0L);
  172.       break;
  173.  
  174.     case IDM_SELALL:
  175.       SendMessage (hWndPostEdit, EM_SETSEL, 0,
  176.                MAKELONG (0, 32767));
  177.       break;
  178.  
  179.     }
  180.       break;
  181.  
  182.  
  183.     case WM_DESTROY:
  184.       hWndPosts[ih] = 0;
  185. #ifndef MAC
  186.       hWndPostEdits[ih] = 0;
  187. #else
  188.       TEDispose (TEHPosts[ih]);
  189.       TEHPosts[ih] = (TEHandle) 0;
  190.       TEHCurrent = 0;
  191. #endif
  192.       break;
  193.  
  194.  
  195.     default:
  196.       return (DefWindowProc (hWnd, message, wParam, lParam));
  197.     }
  198.   return (0L);
  199. }
  200.  
  201. /*--- function StartPost ----------------------------------------------
  202.  *
  203.  *    Start the posting procedure for an article that has been created
  204.  *    by the user.
  205.  *
  206.  *    Entry    ih    is the index into hWndPostEdits of the child
  207.  *                   edit window containing the article.
  208.  */
  209. BOOL
  210. StartPost (ih)
  211.      int ih;
  212. {
  213.   BOOL found;
  214.   BOOL PostOK = FALSE;
  215.   char outline[MAXOUTLINE];
  216.  
  217.   if (CommBusy)
  218.     {
  219.       MessageBox (hWndPosts[ih], "Sorry, I am already busy retrieving information from the server.\n\
  220. Try again in a little while.", "Can't post article right now", MB_OK | MB_ICONASTERISK);
  221.     }
  222.   else
  223.     {
  224.       CommLinePtr = CommLineIn;
  225.       CommBusy = TRUE;
  226.       CommState = ST_POST_WAIT_PERMISSION;
  227.       CommDoc = &(PostingDocs[ih]);
  228.  
  229.       strcpy (outline, "POST");
  230.       PutCommLine (outline, strlen (outline));
  231.       PostOK = TRUE;
  232.     }
  233.   return (PostOK);
  234. }
  235.  
  236. /*--- function PostText -------------------------------------------------
  237.  *
  238.  *    Post the text of an article.  (Second phase of posting process.)
  239.  *
  240.  *    Entry    ih    is the index into hWndPostEdits of the child
  241.  *                   edit window containing the article.
  242.  */
  243. BOOL
  244. PostText (ih, DocType)
  245.      int ih;
  246.      int DocType;
  247. {
  248. #ifndef MAC
  249.   HWND hWndPostEdit;
  250. #else
  251.   TEHandle TEH = TEHPosts[ih];
  252. #endif
  253.   char outline[MAXOUTLINE];
  254.   char *outptr;
  255.   char *editptr;
  256.   HANDLE hEditBuffer;
  257.   int linelen;
  258.   BOOL EndBuf = FALSE;
  259.  
  260. #ifndef MAC
  261.   if (DocType == DOCTYPE_POSTING)
  262.     {
  263.       hWndPostEdit = hWndPostEdits[ih];
  264.       CommState = ST_POST_WAIT_END;
  265.     }
  266.   else
  267.     {
  268.       hWndPostEdit = hWndMailEdits[ih];
  269.       CommState = ST_MAIL_WAIT_END;
  270.     }
  271. #endif
  272.  
  273.   /* Retrieve the text of the edit window, and run through it
  274.    * line by line, sending the lines to the server.
  275.    */
  276. #ifndef MAC
  277.   hEditBuffer = (HANDLE) SendMessage (hWndPostEdit, EM_GETHANDLE, 0, 0L);
  278.   editptr = LocalLock (hEditBuffer);
  279. #else
  280.   hEditBuffer = TEGetText (TEH);
  281.   editptr = LocalLock (hEditBuffer);
  282.   editptr[(*TEH)->teLength] = '\0';
  283.  
  284. #ifdef MRRBUG
  285.   sprintf (outline, "PostText after TEGetText, editptr=%.30s", editptr);
  286.   MessageBox ((HWND) 0, outline, "", MB_OK);
  287. #endif
  288.  
  289. #endif
  290.   while (!EndBuf)
  291.     {
  292.       for (linelen = 0, outptr = outline; *editptr && *editptr != '\r' &&
  293.        linelen < MAXOUTLINE; linelen++)
  294.     *(outptr++) = *(editptr++);
  295.  
  296.       if (linelen == 0) {
  297.         linelen = 1;
  298.         outline[0] = '\r';
  299.       }
  300.       PutCommLine (outline, linelen);
  301. #ifdef MRRBUG
  302.       outline[linelen] = '\0';
  303.       MessageBox ((HWND) 0, outline, "Posted line", MB_OK);
  304. #endif
  305.       if (*editptr == '\r')
  306.     editptr++;
  307.       if (*editptr == '\n')
  308.     editptr++;
  309.       if (!*editptr)
  310.     {
  311.       EndBuf = TRUE;
  312.     }
  313.     }
  314. #if 1
  315.   LocalUnlock (hEditBuffer);
  316. #endif
  317.   PutCommLine (".\r", 2);
  318.   return (TRUE);
  319. }
  320.